package com.xyl.controller;

import com.xyl.commons.ApiResult;
import com.xyl.entity.User;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {
    // 这些对象何以直接被子类使用
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    protected User user;

    @ModelAttribute
    public void setReqAndRes(HttpServletRequest req, HttpServletResponse res) {
        this.request = req;
        this.response = res;
        this.session = req.getSession();
        this.user = (User) this.session.getAttribute("cur_user");
    }

    protected ApiResult resultIsOne(Integer count){
        if(count == 1){
            return new ApiResult();
        }else{
            return new ApiResult(10002,"删除失败!");
        }
    }


}
